package com.jiangyifen.robot.sdkserver.requesthandler;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.jiangyifen.robot.core.Robot;
import com.jiangyifen.robot.sdk.request.Dtmf;
import com.jiangyifen.robot.sdk.request.RequestName;
import com.jiangyifen.robot.sdk.response.BaseResponse;

import io.netty.channel.ChannelHandlerContext;

@Component
public class DtmfHandler extends AbstractRequestHandler<Void>{

	@Override
	public String requestName() {
		return RequestName.dtmf;
	}
	
	@Override
	public BaseResponse<Void> handle(ChannelHandlerContext ctx, String requestId, String requestBody) {
		try {
			Dtmf body = JSON.parseObject(requestBody, Dtmf.class);
			Robot robot = robotService.getRobot(body.getRobotId());
			if(robot==null){
				return BaseResponse.FAIL(requestId, null,"-1","robotId="+body.getRobotId()+"不存在");
			}
			robot.dtmf(body.getDigit());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return BaseResponse.FAIL(requestId, null,"-1",e.getMessage());
		}
		return BaseResponse.SUCCESS(requestId, null);
	}

}
